home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Jotto ][ 1.2 / source / Wipes ƒ / Spiral wipe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.0 KB  |  90 lines  |  [TEXT/MMCC]

  1. #include "timing.h"
  2.  
  3. #define CorrectTime 1
  4. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  5. #define theWindowWidth (boundsRect.right-boundsRect.left)
  6.  
  7. pascal short SpiralGyra(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  8.  
  9. /* Start in the topleft corner, facing downwards.  Copy until you hit (a) the
  10.    edge of the screen, or (b) bits you've already copied.  Then turn counter-
  11.    clockwise and do it again.  */
  12.    
  13. pascal short SpiralGyra(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  14. {
  15.     short            stop,sbottom,sleft,sright,iterrow,itercol,direction;
  16.     Rect            source;
  17.     Boolean            everyOther;
  18.     short            BOXSIZE;
  19.     RgnHandle        boundsRgn;
  20.     
  21.     boundsRgn=NewRgn();
  22.     RectRgn(boundsRgn, &boundsRect);
  23.     BOXSIZE=theWindowHeight/15;
  24.     everyOther=FALSE;
  25.     stop=0;
  26.     sbottom=theWindowHeight/BOXSIZE-(theWindowHeight%BOXSIZE ? 0 : 1);
  27.     sleft=0;
  28.     sright=theWindowWidth/BOXSIZE-(theWindowWidth%BOXSIZE ? 0 : 1);
  29.     direction=3;
  30.     iterrow=stop;
  31.     itercol=sleft;
  32.     while ((stop<=sbottom)&&(sleft<=sright))
  33.     {
  34.         StartTiming();
  35.         source.top=iterrow*BOXSIZE;
  36.         source.bottom=source.top+BOXSIZE;
  37.         source.left=itercol*BOXSIZE;
  38.         source.right=source.left+BOXSIZE;
  39.         OffsetRect(&source, boundsRect.left, boundsRect.top);
  40.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  41.             &source, &source, 0, boundsRgn);
  42.         switch (direction)
  43.         {
  44.             case 0:  /* facing right */
  45.                 if (itercol==sright)
  46.                 {
  47.                     sbottom--;
  48.                     direction++;
  49.                     iterrow--;
  50.                 }
  51.                 else itercol++;
  52.                 break;
  53.             case 1:  /* facing up */
  54.                 if (iterrow==stop)   /* that reads "s top," not "stop" */
  55.                 {
  56.                     sright--;
  57.                     direction++;
  58.                     itercol--;
  59.                 }
  60.                 else iterrow--;
  61.                 break;
  62.             case 2:  /* facing left */
  63.                 if (itercol==sleft)
  64.                 {
  65.                     stop++;
  66.                     direction++;
  67.                     iterrow++;
  68.                 }
  69.                 else itercol--;
  70.                 break;
  71.             case 3:  /* facing down */
  72.                 if (iterrow==sbottom)
  73.                 {
  74.                     sleft++;
  75.                     direction=0;
  76.                     itercol++;
  77.                 }
  78.                 else iterrow++;
  79.                 break;
  80.         }
  81.         if (everyOther)
  82.             TimeCorrection(CorrectTime);
  83.         everyOther=!everyOther;
  84.     }
  85.     
  86.     DisposeRgn(boundsRgn);
  87.     
  88.     return 0;
  89. }
  90.